package com.quarters.util.date;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 时间戳封装类
 */
public class DateUtil {

    //当前系统时间转换成10位时间戳
    public static long Ten(){
        Date date = new Date();
        Long time = date.getTime()/1000;
        return time;
    }

    //当前系统时间转换成13位时间戳
    public static long Thirteen(){
        return System.currentTimeMillis();
    }

    public static String numberDateFormat(String timestamp,String  simpleDateFormatType){
        SimpleDateFormat sdf = new SimpleDateFormat(simpleDateFormatType);//要转换的时间格式
        String date = null;
        if (timestamp.length() == 13){
            date = sdf.format(Long.parseLong(timestamp));
        }else{
            date = sdf.format(Long.parseLong(timestamp)*1000);
        }
        return date;
    }
    /**
     * 时间戳转换成日期格式字符串
     * @param seconds 精确到秒的字符串
     * @return
     */
    public static String timeStamp2Date(String seconds,String format) {
        if(seconds == null || seconds.isEmpty() || seconds.equals("null")){
            return "";
        }
        if(format == null || format.isEmpty()){
            format = "yyyy-MM-dd HH:mm:ss";
        }
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        return sdf.format(new Date(Long.valueOf(seconds+"000")));
    }
    /**
     * 日期格式字符串转换成时间戳
     * @param format 如：yyyy-MM-dd HH:mm:ss
     * @return
     */
    public static Long date2TimeStamp(String date_str,String format){
        try {
            SimpleDateFormat sdf = new SimpleDateFormat(format);
            return sdf.parse(date_str).getTime()/1000;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }


    //将日期格式转换成13位时间戳
    public static long data(String data){
        Date d = new Date();
        try {
            SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
            d = sf.parse(data);// 日期转换为时间戳
        } catch (ParseException e) {
            e.printStackTrace();
        }
        long timeStemp = d.getTime();
        return timeStemp;
    }



}
